package com.transpot.controller.customer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.transpot.entry.customer.CustomerDTO;
import com.transpot.entry.customer.CustomerSearchDTO;
import com.transpot.entry.customer.CustomerVO;
import com.transpot.entry.customer.UpdateCustomerDTO;
import com.transpot.service.customer.CustomerService;
import com.transpot.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 客户类的控制层代码
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    /**
     * 保存客户信息的接口方法，用来接收前端发来的数据，并且调用service层代码处理数据
     * @return
     */
    @PostMapping("/saveCustomerInfo")
    public R saveCustomerInfo(@RequestBody CustomerDTO customerDTO) {
        customerService.saveCustomerInfo(customerDTO);
        return R.success();
    }

    /**
     * 根据搜索条件分页查询客户信息列表的接口方法
     * @return
     */
    @GetMapping("/getCustomerByConditionAndPage")
    public R getCustomerByCondtiionAndPage(CustomerSearchDTO customerSearchDTO) {
        //调用service层方法，获取到MP的分页对象
        IPage<CustomerVO> customerVOIPage = customerService.getCustomerByConditionAndPage(customerSearchDTO);
        return R.success(customerVOIPage);
    }

    /**
     * 根据客户ID删除客户信息的接口方法
     * @param id
     * @return
     */
    @DeleteMapping("/deleteCustomerById")
    public R deleteCustomerById(Integer id) {
        customerService.deleteCustomerById(id);
        return R.success();
    }

    /**
     * 根据客户ID修改客户信息的接口方法
     * @param updateCustomerDTO
     * @return
     */
    @PutMapping("/updateCustomerById")
    public R updateCustomerById(@RequestBody UpdateCustomerDTO updateCustomerDTO) {
        customerService.updateCustomerById(updateCustomerDTO);
        return R.success();
    }
}
